﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        /*
        public static dynamic getCProblemRanklist(int pid, int start,int limit, string username)
        {
            var sql = new Sql.SqlDataContext();
            if(!sql.ContestProblem.Any(row => row.pid == pid)) return new{
                success = false,
                msg = "题目不存在"
            };

            var sos = sql.ContestSolve.Where(row => row.pid == pid && row.ac > 0);
            var total = sos.Count();

            var result = (from so in sos
                          from s in sql.ContestStatus
                          from u in sql.User
                          from l in sql.Language
                          where s.rid == so.bestRid && u.username == so.username && l.code == s.lang
                          orderby s.exeTime, s.exeMem, s.code.Length, s.rid
                          select new
                          {
                              rank = (from so2 in sql.ContestSolve
                                      from s2 in sql.ContestStatus
                                      where so2.pid == pid && so2.ac > 0 && s2.rid == so2.bestRid &&
                                      (s2.exeTime < s.exeTime ||
                                      (s2.exeTime == s.exeTime && (s2.exeMem < s.exeMem ||
                                      (s2.exeMem == s.exeMem && s2.code.Length < s.code.Length))))
                                      select so2).Count() + 1,
                              s.rid,
                              so.username,
                              lang = l.title,
                              langCode = s.lang,
                              codeLen = s.code.Length,
                              allowCode = s.username == username,
                              s.exeTime,
                              s.exeMem,
                              submitTime = s.submitTime.toTimeString(),
                          }).Skip(start).Take(limit);

            return new
            {
                success = true,
                total,
                result
            };
        }
         * */
    }
}
